package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.pojo.entity.MuseumNotice;
import com.shaobufan.museum.pojo.request.notice.NoticeAddRequest;
import com.shaobufan.museum.service.MuseumNoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公告请求
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    MuseumNoticeService museumNoticeService;

    @ApiOperation("获取全部公告")
    @GetMapping("/all")
    public BaseResponse<List<MuseumNotice>> getAllNotice() {
        List<MuseumNotice> museumNoticeList = museumNoticeService.getMuseumNotice();
        return ResultUtils.success(museumNoticeList, "全部公告");
    }

    @ApiOperation("添加公告")
    @PostMapping("/add")
    public BaseResponse<Boolean> setNotice(@RequestBody NoticeAddRequest noticeAddRequest) {
        String noticeTitle = noticeAddRequest.getNoticeTitle();
        String noticeContent = noticeAddRequest.getNoticeContent();

        Boolean addMuseumNotice = museumNoticeService.addMuseumNotice(noticeTitle, noticeContent);
        return ResultUtils.success(addMuseumNotice, "添加成功");
    }
}